package com.tedu.show.menus;

import com.tedu.controller.GameController;
import com.tedu.manager.MusicManager;

import javax.swing.*;
import java.awt.*;

public class SettingsScreen extends BaseScreen {

    public SettingsScreen() {
        super("game_start");

        // 音量标签
        JLabel volumeLabel = new JLabel("音量调节");
        volumeLabel.setBounds(350, 250, 100, 30);
        volumeLabel.setForeground(Color.WHITE); // 设置字体颜色
        volumeLabel.setFont(new Font("宋体", Font.BOLD, 16));
        this.add(volumeLabel);

        // 音量滑动条
        JSlider volumeSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, MusicManager.getInstance().getVolume());
        volumeSlider.setBounds(250, 290, 300, 50);
        volumeSlider.setMajorTickSpacing(20); // 主刻度间距
        volumeSlider.setMinorTickSpacing(10); // 次刻度间距
        volumeSlider.setPaintTicks(true);    // 显示刻度
        volumeSlider.setPaintLabels(true);   // 显示数字标签
        volumeSlider.setOpaque(false);       // 使背景透明
        volumeSlider.setForeground(Color.WHITE);

        // 添加监听器，当滑动条值改变时，实时设置音量
        volumeSlider.addChangeListener(e -> {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) { // 仅在用户释放滑块后设置
                MusicManager.getInstance().setVolume(source.getValue());
            }
        });
        this.add(volumeSlider);

        // 返回按钮
        JButton backButton = new JButton("返回");
        backButton.setBounds(300, 400, 200, 50);
        backButton.addActionListener(e -> GameController.switchPanel(GameController.GameState.SELECTION));
        this.add(backButton);
    }
}
